package homegroup.inc.servlets;

import homegroup.inc.dao.BookDAO;
import homegroup.inc.dto.Book;

import javax.ejb.EJB;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "bookdetails", urlPatterns = "/book/*")
public class BookDetails extends HttpServlet {
    @EJB
    BookDAO bookDAO;
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String isbn = request.getParameter("isbn");
        Book book = bookDAO.findByISBN(isbn);
        request.setAttribute("book", book);
        RequestDispatcher dispatcher = request.getRequestDispatcher("/view/bookdetails.jsp");
        dispatcher.forward(request, response);
    }
}
